Skip to main content
Glama

Gitlab Search User Projects Tool

Search user profiles and active projects on GitLab using a username. Filter API response fields to retrieve specific data efficiently.

Instructions

根据用户名搜索用户信息及其活跃项目。支持字段过滤,提升响应效率。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldsNo需要返回的字段路径数组,支持数组或逗号分隔字符串,用于过滤 API 响应字段。 示例: - ["id", "name", "owner.username"] - "id,name,owner.username" - undefined
usernameYes用户名

Implementation Reference

  • The main handler function implementing the tool logic: searches GitLab users by username, fetches their projects, applies optional field filtering, and returns JSON result or error message.
    async execute(args: unknown, context: Context<Record<string, unknown> | undefined>) { const typedArgs = args as { username: string; fields?: string[] | string; }; try { const client = createGitlabClientFromContext(context); const users = await client.apiRequest("/users", "GET", { search: typedArgs.username }); if (!Array.isArray(users) || users.length === 0) { return { content: [ { type: "text", text: `未找到用户名为 ${typedArgs.username} 的用户` } ], isError: true }; } const user = users[0]; const projects = await client.apiRequest(`/users/${user.id}/projects`, "GET", {}); const result = { user, projects }; if (typedArgs.fields) { const fieldsArray = Array.isArray(typedArgs.fields) ? typedArgs.fields : typedArgs.fields.split(",").map(f => f.trim()).filter(f => f); const filteredResult = filterResponseFields(result, fieldsArray); return { content: [{ type: "text", text: JSON.stringify(filteredResult) }] } as ContentResult; } else { return { content: [{ type: "text", text: JSON.stringify(result) }] } as ContentResult; } } catch (error: any) { return { content: [ { type: "text", text: `GitLab MCP 工具调用异常:${error?.message || String(error)}` } ], isError: true }; } },
  • Tool metadata including name, description, and Zod input schema for 'username' (required string) and 'fields' (optional for filtering).
    name: "Gitlab Search User Projects Tool", description: "根据用户名搜索用户信息及其活跃项目。支持字段过滤,提升响应效率。", parameters: z.object({ username: z.string().describe("用户名"), fields: createFieldsSchema(), }),
  • The tool is included in the fastmcpTools array used for registration with FastMCP servers.
    const fastmcpTools = [ GitlabAcceptMRTool, GitlabCreateMRCommentTool, GitlabCreateMRTool, GitlabGetUserTasksTool, GitlabRawApiTool, GitlabSearchProjectDetailsTool, GitlabSearchUserProjectsTool, GitlabUpdateMRTool, ];
  • Mapping from the tool's original name to the standardized GitLabToolName used in filtering and type definitions.
    const toolNameMapping = { [GitlabSearchUserProjectsTool.name]: "Gitlab_Search_User_Projects_Tool", [GitlabGetUserTasksTool.name]: "Gitlab_Get_User_Tasks_Tool", [GitlabSearchProjectDetailsTool.name]: "Gitlab_Search_Project_Details_Tool", [GitlabCreateMRTool.name]: "Gitlab_Create_MR_Tool", [GitlabUpdateMRTool.name]: "Gitlab_Update_MR_Tool", [GitlabAcceptMRTool.name]: "Gitlab_Accept_MR_Tool", [GitlabCreateMRCommentTool.name]: "Gitlab_Create_MR_Comment_Tool", [GitlabRawApiTool.name]: "Gitlab_Raw_API_Tool", } as const;
  • Import of the tool definition for use in registration.
    import { GitlabSearchUserProjectsTool } from "./tools/GitlabSearchUserProjectsTool";

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ZephyrDeng/mcp-server-gitlab'

If you have feedback or need assistance with the MCP directory API, please join our Discord server